# -----------------------------------------------
# Author: yuz
# Copyright: 湖南零檬信息技术有限公司
# Email: wagyu2016@163.com
# Phone&Wechat: 18173179913
# Site: http://www.lemonban.com
# Forum: http://testingpai.com
# -----------------------------------------------
import time
from base64 import b64encode

import rsa as rsa


def get_sign(ts, token):
    s = token[:50] + str(ts)
    key ='-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQENQujkLfZfc5Tu9Z1LprzedE\nO3F7g s+7bzrgPsMl29LX8UoPYvIG8C604CprBQ4FkfnJpnhWu2lvUB0WZyLq6sBr\ntuPorOc42+gLnFfyhJAw dZB6SqWfDg7bW+jNe5Ki1DtU7z8uF6Gx+blEMGo8Dg+S\nkKlZFc8Br7SHtbL2tQIDAQAB\n-----END PUBLIC KEY-----\n'
    public_key = rsa.PublicKey.load_pkcs1_openssl_pem(key.encode())
    enctypred = rsa.encrypt(s.encode(), public_key)
    return b64encode(enctypred).decode()

# a = get_sign("username", 'id')
# print(a)



def get_sign_new(plain):
    key = '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQENQujkLfZfc5Tu9Z1LprzedE\nO3F7g s+7bzrgPsMl29LX8UoPYvIG8C604CprBQ4FkfnJpnhWu2lvUB0WZyLq6sBr\ntuPorOc42+gLnFfyhJAw dZB6SqWfDg7bW+jNe5Ki1DtU7z8uF6Gx+blEMGo8Dg+S\nkKlZFc8Br7SHtbL2tQIDAQAB\n-----END PUBLIC KEY-----\n'
    public_key = rsa.PublicKey.load_pkcs1_openssl_pem(key.encode())
    enctypred = rsa.encrypt(plain.encode(), public_key)
    return b64encode(enctypred).decode()
    # return enctypred

if __name__ == '__main__':
    result = get_sign_new('hello')
    print(result)